package com.jhhc.Liunx;



import com.jhhc.Liunx.Pojo.Liunx;
import com.jhhc.Liunx.Util.GetLiunxInfo;
import com.jhhc.utils.JsonResult;
import com.jhhc.Liunx.Util.OSUtils;
import com.jhhc.utils.SigarUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hyperic.sigar.SigarException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping(value = "Liunx", headers = "Accept=application/json")
@RestController
@Api(value="LiunxController",tags={"Liunx服务"})
public class LiunxController {
    @Autowired
    private com.jhhc.utils.GetDataService GetDataService;

    @ApiOperation("查询Liunx服务器参数")
    @RequestMapping(value = "Data/GetLiunxData", headers = "Accept=application/json", method = RequestMethod.GET)
    public JsonResult GetLiunx(){
        JsonResult JsonResult = new JsonResult();
        Liunx liunx = new Liunx();
        //ip
        liunx.setIp(OSUtils.getInet4Address());
        //CPU使用率
        liunx.setCpuUtilization(OSUtils.cpuUsage());
        //cpuinfo
        liunx.setCpuinfo(OSUtils.cpuinfo());
        //disk可用磁盘
        liunx.setAvailableDisk(OSUtils.disk());
        //disk 使用率
        try {
            liunx.setDiskUsage((int)OSUtils.getDeskUsage());
        } catch (Exception e) {
            e.printStackTrace();
        }
        //内存使用率
        liunx.setMemoryUsage(OSUtils.memoryUsage());
        //内存大小
        liunx.setMemSize((int) OSUtils.getMemSize());

        JsonResult.setSucceeded(true);
        JsonResult.setStatusCode(200);
        JsonResult.setData(liunx);
        return  JsonResult;
    }

}
